package com.example.provider;


import com.example.provider.services.impl.UserServersImpl;
import com.example.rpc_core.RpcApplication;
import com.example.rpc_core.config.RegistryConfig;
import com.example.rpc_core.config.RpcConfig;
import com.example.rpc_core.constance.RpcConstant;
import com.example.rpc_core.model.ServiceInfo;
import com.example.rpc_core.register.Register;
import com.example.rpc_core.register.RegistryFactory;
import com.example.rpc_core.register.impl.LocalRegister;
import com.example.rpc_core.servers.HttpServer;
import com.example.rpc_core.servers.HttpServerImpl;
import com.example.provider.services.UserServices;
import com.example.rpc_core.servers.TcpServerImpl;


public class EasyProvider {
//    /**
//     * 启动服务
//     * @param args
//     */
//    public static void main(String[] args) {
//
//                // RPC 框架初始化
//                RpcApplication.init();
//
//                // 注册服务
//                String serviceName = UserServices.class.getName();
//                LocalRegister.register(serviceName, UserServersImpl.class);
//
//                // 注册服务到注册中心
//                RpcConfig rpcConfig = RpcApplication.getRpcConfig();
//                RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
//                Register registry = RegistryFactory.getRegistry(registryConfig.getRegistryType());
//                ServiceInfo serviceMetaInfo = new ServiceInfo();
//                serviceMetaInfo.setServiceName(serviceName);
//                serviceMetaInfo.setServiceHost(rpcConfig.getHost());
//                serviceMetaInfo.setServicePort(rpcConfig.getPort());
//                try {
//                    registry.register(serviceMetaInfo);
//                } catch (Exception e) {
//                    throw new RuntimeException(e);
//                }
//
//                // 启动 web 服务
//                HttpServer httpServer = new HttpServerImpl();
//                httpServer.startService(RpcApplication.getRpcConfig().getPort());



            public static void main(String[] args) {
                // RPC 框架初始化
                RpcApplication.init();
                // 注册服务
                String serviceName = UserServices.class.getName();
                LocalRegister.register(serviceName, UserServersImpl.class);
                // 注册服务到注册中心
                RpcConfig rpcConfig = RpcApplication.getRpcConfig();
                RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
                Register registry = RegistryFactory.getRegistry(registryConfig.getRegistryType());
                ServiceInfo serviceMetaInfo = new ServiceInfo();
                serviceMetaInfo.setServiceName(serviceName);
                serviceMetaInfo.setServiceHost(rpcConfig.getHost());
                serviceMetaInfo.setServicePort(rpcConfig.getPort());
                try {
                    registry.register(serviceMetaInfo);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                // 启动 TCP 服务
                TcpServerImpl vertxTcpServer = new TcpServerImpl();
                vertxTcpServer.startService(8081);


    }
}
